package com.woniu.fly.fairmall.db.service;


import com.github.pagehelper.PageHelper;
import com.woniu.fly.fairmall.db.dao.FairmallManagerDao;
import com.woniu.fly.fairmall.db.entity.FairmallManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 管理员表(FairmallManager)表服务实现类
 *
 * @author makejava
 * @since 2020-03-19 14:23:06
 */
@Service("fairmallManagerService")
public class FairmallManagerService {
    @Resource
    private FairmallManagerDao fairmallManagerDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    public FairmallManager queryById(Long id) {
        return this.fairmallManagerDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    public List<FairmallManager> queryAllByLimit(int offset, int limit) {
        return this.fairmallManagerDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param fairmallManager 实例对象
     * @return 实例对象
     */
    public FairmallManager insert(FairmallManager fairmallManager) {
        this.fairmallManagerDao.insert(fairmallManager);
        return fairmallManager;
    }

    /**
     * 修改数据
     *
     * @param fairmallManager 实例对象
     * @return 实例对象
     */
    public int update(FairmallManager fairmallManager) {
        fairmallManager.setUpdateTime(LocalDateTime.now());
        return fairmallManagerDao.update(fairmallManager);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    public boolean deleteById(Long id) {
        return this.fairmallManagerDao.deleteById(id) > 0;
    }

    public List<FairmallManager> queryListByPage(String username, Integer page, Integer limit) {
        FairmallManager admin = new FairmallManager();
        admin.setUsername(username);
        PageHelper.startPage(page, limit);
        return fairmallManagerDao.queryAll(admin);
    }

    public List<FairmallManager> queryAll(FairmallManager fairmallManager) {
        return fairmallManagerDao.queryAll(fairmallManager);
    }
}
